<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-ux-grid-filter-ListFilter'>/**
</span> * @class Ext.ux.grid.filter.ListFilter
 * @extends Ext.ux.grid.filter.Filter
 * &lt;p&gt;List filters are able to be preloaded/backed by an Ext.data.Store to load
 * their options the first time they are shown. ListFilter utilizes the
 * {@link Ext.ux.grid.menu.ListMenu} component.&lt;/p&gt;
 * &lt;p&gt;Although not shown here, this class accepts all configuration options
 * for {@link Ext.ux.grid.menu.ListMenu}.&lt;/p&gt;
 *
 * &lt;p&gt;&lt;b&gt;&lt;u&gt;Example Usage:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
 * &lt;pre&gt;&lt;code&gt;
var filters = Ext.create('Ext.ux.grid.GridFilters', {
    ...
    filters: [{
        type: 'list',
        dataIndex: 'size',
        phpMode: true,
        // options will be used as data to implicitly creates an ArrayStore
        options: ['extra small', 'small', 'medium', 'large', 'extra large']
    }]
});
 * &lt;/code&gt;&lt;/pre&gt;
 *
 */
Ext.define('Ext.ux.grid.filter.ListFilter', {
    extend: 'Ext.ux.grid.filter.Filter',
    alias: 'gridfilter.list',

<span id='Ext-ux-grid-filter-ListFilter-cfg-options'>    /**
</span>     * @cfg {Array} options
     * &lt;p&gt;&lt;code&gt;data&lt;/code&gt; to be used to implicitly create a data store
     * to back this list when the data source is &lt;b&gt;local&lt;/b&gt;. If the
     * data for the list is remote, use the &lt;code&gt;{@link #store}&lt;/code&gt;
     * config instead.&lt;/p&gt;
     * &lt;br&gt;&lt;p&gt;Each item within the provided array may be in one of the
     * following formats:&lt;/p&gt;
     * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
     * &lt;li&gt;&lt;b&gt;Array&lt;/b&gt; :
     * &lt;pre&gt;&lt;code&gt;
options: [
    [11, 'extra small'],
    [18, 'small'],
    [22, 'medium'],
    [35, 'large'],
    [44, 'extra large']
]
     * &lt;/code&gt;&lt;/pre&gt;
     * &lt;/li&gt;
     * &lt;li&gt;&lt;b&gt;Object&lt;/b&gt; :
     * &lt;pre&gt;&lt;code&gt;
labelField: 'name', // override default of 'text'
options: [
    {id: 11, name:'extra small'},
    {id: 18, name:'small'},
    {id: 22, name:'medium'},
    {id: 35, name:'large'},
    {id: 44, name:'extra large'}
]
     * &lt;/code&gt;&lt;/pre&gt;
     * &lt;/li&gt;
     * &lt;li&gt;&lt;b&gt;String&lt;/b&gt; :
     * &lt;pre&gt;&lt;code&gt;
     * options: ['extra small', 'small', 'medium', 'large', 'extra large']
     * &lt;/code&gt;&lt;/pre&gt;
     * &lt;/li&gt;
     */
<span id='Ext-ux-grid-filter-ListFilter-cfg-phpMode'>    /**
</span>     * @cfg {Boolean} phpMode
     * &lt;p&gt;Adjust the format of this filter. Defaults to false.&lt;/p&gt;
     * &lt;br&gt;&lt;p&gt;When GridFilters &lt;code&gt;@cfg encode = false&lt;/code&gt; (default):&lt;/p&gt;
     * &lt;pre&gt;&lt;code&gt;
// phpMode == false (default):
filter[0][data][type] list
filter[0][data][value] value1
filter[0][data][value] value2
filter[0][field] prod

// phpMode == true:
filter[0][data][type] list
filter[0][data][value] value1, value2
filter[0][field] prod
     * &lt;/code&gt;&lt;/pre&gt;
     * When GridFilters &lt;code&gt;@cfg encode = true&lt;/code&gt;:
     * &lt;pre&gt;&lt;code&gt;
// phpMode == false (default):
filter : [{&quot;type&quot;:&quot;list&quot;,&quot;value&quot;:[&quot;small&quot;,&quot;medium&quot;],&quot;field&quot;:&quot;size&quot;}]

// phpMode == true:
filter : [{&quot;type&quot;:&quot;list&quot;,&quot;value&quot;:&quot;small,medium&quot;,&quot;field&quot;:&quot;size&quot;}]
     * &lt;/code&gt;&lt;/pre&gt;
     */
    phpMode : false,
<span id='Ext-ux-grid-filter-ListFilter-cfg-store'>    /**
</span>     * @cfg {Ext.data.Store} store
     * The {@link Ext.data.Store} this list should use as its data source
     * when the data source is &lt;b&gt;remote&lt;/b&gt;. If the data for the list
     * is local, use the &lt;code&gt;{@link #options}&lt;/code&gt; config instead.
     */

<span id='Ext-ux-grid-filter-ListFilter-method-init'>    /**
</span>     * @private
     * Template method that is to initialize the filter.
     * @param {Object} config
     */
    init : function (config) {
        this.dt = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
    },

<span id='Ext-ux-grid-filter-ListFilter-method-createMenu'>    /**
</span>     * @private @override
     * Creates the Menu for this filter.
     * @param {Object} config Filter configuration
     * @return {Ext.menu.Menu}
     */
    createMenu: function(config) {
        var menu = Ext.create('Ext.ux.grid.menu.ListMenu', config);
        menu.on('checkchange', this.onCheckChange, this);
        return menu;
    },

<span id='Ext-ux-grid-filter-ListFilter-method-getValue'>    /**
</span>     * @private
     * Template method that is to get and return the value of the filter.
     * @return {String} The value of this filter
     */
    getValue : function () {
        return this.menu.getSelected();
    },
<span id='Ext-ux-grid-filter-ListFilter-method-setValue'>    /**
</span>     * @private
     * Template method that is to set the value of the filter.
     * @param {Object} value The value to set the filter
     */
    setValue : function (value) {
        this.menu.setSelected(value);
        this.fireEvent('update', this);
    },

<span id='Ext-ux-grid-filter-ListFilter-method-isActivatable'>    /**
</span>     * @private
     * Template method that is to return &lt;tt&gt;true&lt;/tt&gt; if the filter
     * has enough configuration information to be activated.
     * @return {Boolean}
     */
    isActivatable : function () {
        return this.getValue().length &gt; 0;
    },

<span id='Ext-ux-grid-filter-ListFilter-method-getSerialArgs'>    /**
</span>     * @private
     * Template method that is to get and return serialized filter data for
     * transmission to the server.
     * @return {Object/Array} An object or collection of objects containing
     * key value pairs representing the current configuration of the filter.
     */
    getSerialArgs : function () {
        return {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
    },

<span id='Ext-ux-grid-filter-ListFilter-method-onCheckChange'>    /** @private */
</span>    onCheckChange : function(){
        this.dt.delay(this.updateBuffer);
    },


<span id='Ext-ux-grid-filter-ListFilter-method-validateRecord'>    /**
</span>     * Template method that is to validate the provided Ext.data.Record
     * against the filters configuration.
     * @param {Ext.data.Record} record The record to validate
     * @return {Boolean} true if the record is valid within the bounds
     * of the filter, false otherwise.
     */
    validateRecord : function (record) {
        var valuesArray = this.getValue();
        return Ext.Array.indexOf(valuesArray, record.get(this.dataIndex)) &gt; -1;
    }
});
</pre>
</body>
</html>
